<?php function formatSize($size) {
	if($size == 0)
		return null;

	$sizes = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
	return (round($size/pow(1024, ($i = floor(log($size, 1024)))), $i > 1 ? 2 : 0) . $sizes[$i]);
} ?>
<?php include "menu.phtml"; ?>
<div id="right">
	<div class="rightbox">
		<div class="context"><div class="in"><a href="javascript:void(0);" id="context_menu" class="icon_link the_down"><span></span></a></div></div>
		<h1><?php echo $this->translate->_("Attach Files"); ?></h1>
		<br />
		<?php if(isset($this->up['errors']) && count($this->up['errors']) > 0):?>
			<div class="c_error">
				<?php foreach($this->up['errors'] as $idx => $error): ?>
					<div><b><?php echo $idx; ?></b></div>
					<ul>
						<?php foreach($error as $item): ?>
							<li><?php echo $item; ?></li>
						<?php endforeach; ?>
					</ul>
				<?php endforeach; ?>
			</div>
			<br />
		<?php endif; ?>
		<?php if(isset($this->up['success']) && count($this->up['success']) > 0):?>
			<div class="c_success">
				<ul>
					<?php foreach($this->up['success'] as $idx => $success): ?>
						<li><?php echo $idx; ?> <?php echo $this->translate->_("was successfully uploaded"); ?>.</li>
					<?php endforeach; ?>
				</ul>
			</div>
			<br />
		<?php endif; ?>
		<?php echo $this->form; ?>
		<?php if(isset($this->files) && count($this->files) > 0): ?>
			<br />
			<table cellspacing="0" cellpadding="5" class="grid">
				<col width="20" /><col width="430" /><col width="100" /><col width="140" /><col width="100" />
				<tr>
					<th></th>
					<th><?php echo $this->translate->_("Name"); ?></th>
					<th style="text-align: right;"><?php echo $this->translate->_("Size"); ?></th>
					<th style="text-align: center;"><?php echo $this->translate->_("Modified"); ?></th>
					<th style="text-align: right;"></th>
				</tr>
				<?php foreach($this->files as $file): ?>
					<tr>
						<td><img src="<?php echo "/images/files/{$file->getIcon()}"; ?>" alt="" /></td>
						<td><a href="<?php echo $this->url(array('controller'=>'pets', 'action'=>'files', 'download'=>$file->getId()), 'default', true); ?>"><?php echo $file->getDescription(); ?></a></td>
						<td align="right"><?php echo formatSize($file->getSize() * 1024); ?></td>
						<td align="center"><?php echo Petolio_Service_Util::formatDate($file->getDateModified() ? $file->getDateModified() : $file->getDateCreated(), Petolio_Service_Util::MEDIUMDATE, true, true); ?></td>
						<td align="right" nowrap="nowrap"><a href="<?php echo $this->url(array('controller'=>'pets', 'action'=>'files', 'remove'=>$file->getId()), 'default', true); ?>" class="icon_link delete reqconf" title="<?php echo $this->translate->_('Are you sure you want to delete this file?'); ?>"><span><?php echo $this->translate->_("Delete"); ?></span></a></td>
					</tr>
				<?php endforeach; ?>
			</table>
			<br />
		<?php else: ?>
			<hr />
		<?php endif; ?>
		<div class="left"><input onclick="Petolio.go(window.location.href.replace('attach', 'edit'));" type="button" value="<?php echo $this->translate->_("< Go Back to Edit"); ?>" id="submit" name="prev" style="margin: 0px;"><div class="clear"></div></div>
		<div class="right"><input onclick="Petolio.go('<?php echo $this->url(array('controller'=>'medical', 'action'=>'view', 'id'=>($this->record ? $this->record->getId() : $this->subentry->getMedicalRecordId())), 'default', true); ?>');" type="button" value="<?php echo $this->translate->_("Finish >"); ?>" id="submit" name="next"><div class="clear"></div></div>
		<div class="clear"></div>
	</div>
</div>